package com.hz.score.search.controller;

import com.hz.score.common.dto.PageDto;
import com.hz.score.search.document.CommData;
import com.hz.score.search.document.EntScore;
import com.hz.score.search.document.IndData;
import com.hz.score.search.document.LabData;
import com.hz.score.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "企业查询筛选类", description = "通过企业信息、经营信息、企业指标、企业积分、企业标签筛选企业")
@Controller
@RequestMapping("/search")
public class SearchController {

    @Resource
    SearchService searchService;

    @ApiOperation("按年份查询单条企业画像信息")
    @PostMapping("/get")
    @ResponseBody
    private EntScore pageEnt(@RequestParam(value = "creditCode", defaultValue = "10") String creditCode,
                             @RequestParam(value = "dataYear", defaultValue = "10") String dataYear) {
        return searchService.getEntScore(creditCode, dataYear);
    }

    @ApiOperation("分页查询企业画像信息")
    @PostMapping("/page")
    @ResponseBody
    private PageDto<EntScore> pageEnt(@RequestBody EntScore entScore,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "sortInfo", defaultValue = "") String sortInfo) {
        return searchService.pageScoreByYear(entScore, pageSize, pageNum, sortInfo);
    }

    @ApiOperation("聚合查询企业画像信息")
    @PostMapping("/aggregate")
    @ResponseBody
    private List<Map> aggregateEnt(@RequestBody EntScore entScore,
                                   @RequestParam(value = "groupInfo", defaultValue = "") String groupInfo) {
        return searchService.pageScoreByYear(entScore, groupInfo);
    }

    @ApiOperation("按年份设置企业经营信息值")
    @PostMapping("/setEntCommVal")
    @ResponseBody
    private void setEntCommVal(@RequestBody EntScore entScore) {
        List<CommData> commDataList = entScore.getCommDataList();
        if (commDataList != null) {
            searchService.setCommDataVal(entScore.getCreCod(), entScore.getDataYear(), commDataList);
        }
    }

    @ApiOperation("按年份设置企业指标值")
    @PostMapping("/setEntIndVal")
    @ResponseBody
    private void setEntIndVal(@RequestBody EntScore entScore) {
        List<IndData> indDataList = entScore.getIndDataList();
        if (indDataList != null) {
            searchService.setIndDataVal(entScore.getCreCod(), entScore.getDataYear(), indDataList);
        }
    }

    @ApiOperation("按年份设置企业指标得分")
    @PostMapping("/setEntIndSco")
    @ResponseBody
    private void setEntIndSco(@RequestBody EntScore entScore) {
        List<IndData> indDataList = entScore.getIndDataList();
        if (indDataList != null) {
            searchService.setIndDataSco(entScore.getCreCod(), entScore.getDataYear(), indDataList);
        }
    }

    @ApiOperation("按年份设置企业标签")
    @PostMapping("/newEntLab")
    @ResponseBody
    private void setEntLab(@RequestBody EntScore entScore) {
        List<LabData> labDataList = entScore.getLabDataList();
        if (labDataList != null) {
            searchService.newLabData(entScore.getCreCod(), entScore.getDataYear(), labDataList);
        }
    }

    @ApiOperation("按年份更新企业标签状态")
    @PostMapping("/setEntLabStatus")
    @ResponseBody
    private void setEntLabStatus(@RequestBody EntScore entScore) {
        List<LabData> labDataList = entScore.getLabDataList();
        if (labDataList != null) {
            searchService.setValidLabData(entScore.getCreCod(), entScore.getDataYear(), labDataList);
        }
    }

    @ApiOperation("按年份删除企业标签")
    @PostMapping("/delEntLab")
    @ResponseBody
    private void delEntLab(@RequestBody EntScore entScore) {
        List<LabData> labDataList = entScore.getLabDataList();
        if (labDataList != null) {
            searchService.delLabData(entScore.getCreCod(), entScore.getDataYear(), labDataList);
        }
    }
}
